const app = getApp()
const constant = require("../../../../constant.js")
const storage = require("../../../../utils/storage.js")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    showIndex: [true,true,true,true,true,true,true,true],/* 是否展开：心肺、基础力量、妈妈学员、体态、体态-静态正面站姿、体态-静态背面站姿、体态-自重深蹲、关节*/
    popupShow:false,
    allDiseases: [
      { value: 'HYPERTENSION', description: '高血压', check: false },
      { value: 'HYPOTENSION', description: '低血压', check: false },
      { value: 'GOUT', description: '痛风', check: false },
      { value: 'CARDIOPATHY', description: '心脏病', check: false },
      { value: 'SPONDYLOSIS', description: '脊椎病', check: false }
    ],
    bobiTypes: [
      { name: '标准', value: true },
      { name: '简化', value: false }
    ],
    vUps: [
      { name: '<10s', value: 'LEVELONE' },
      { name: '10-15', value: 'LEVELTWO' },
      { name: '16-20', value: 'LEVELTHREE' },
      { name: '>20', value: 'LEVELFOUR' }
    ],
    staticSquats: [
      { name: '<30s', value: 'LEVELONE' },
      { name: '30-60s', value: 'LEVELTWO' },
      { name: '61-90s', value: 'LEVELTHREE' },
      { name: '>90s', value: 'LEVELFOUR' }
    ],
    pushUps: [
      { name: '<10s', value: 'LEVELONE' },
      { name: '10-20', value: 'LEVELTWO' },
      { name: '20-30', value: 'LEVELTHREE' },
      { name: '30', value: 'LEVELFOUR' }
    ],
    rectusAbdominisIsolations: [
      { name: '正常', value: 'NORMAL' },
      { name: '1指', value: 'ONE' },
      { name: '2指', value: 'TWO' },
      { name: '3指', value: 'THREE' },
      { name: '3指以上', value: 'MORE' }
    ],
    obverseHeads: [
      { name: '中立位', value: 'NORMAL' },
      { name: '前引', value: 'LEFT' },
      { name: '后仰', value: 'RIGHT' }
    ],
    obverseScapulas: [
      { name: '中立位', value: 'NORMAL' },
      { name: '圆肩', value: 'UNNORMAL' }
    ],
    obversePelviss: [
      { name: '中立位', value: 'NORMAL' },
      { name: '前倾', value: 'LEFT' },
      { name: '后倾', value: 'RIGHT' }
    ],
    obverseKneeJoints: [
      { name: '中立位', value: 'NORMAL' },
      { name: '膝外翻', value: 'LEFT' },
      { name: '膝内翻', value: 'RIGHT' }
    ],
    reverseHeads: [
      { name: '中立位', value: 'NORMAL' },
      { name: '侧倾', value: 'UNNORMAL' }
    ],
    reverseCervicalVertebras: [
      { name: '中立位', value: 'NORMAL' },
      { name: '扭转', value: 'UNNORMAL' }
    ],
    reverseHipJoints: [
      { name: '中立位', value: 'NORMAL' },
      { name: '左高', value: 'LEFT' },
      { name: '右高', value: 'RIGHT' }
    ],
    reverseKneeJoints: [
      { name: '中立位', value: 'NORMAL' },
      { name: '超伸', value: 'UNNORMAL' }
    ],
    reverseFoots: [
      { name: '正常', value: 'NORMAL' },
      { name: '扁平足', value: 'UNNORMAL' }
    ],
    kneeDirections: [
      { name: '正常', value: 'NORMAL' },
      { name: '内扣', value: 'LEFT' },
      { name: '外扣', value: 'RIGHT' }
    ],
    parallels: [
      { name: '是', value: true},
      { name: '否', value: false}
    ],
    joints: [
      { name: '良好', value: 'GOOD' },
      { name: '不足', value: 'LACKING' },
      { name: '严重受限', value: 'AWFUL' }
    ],
    disabled: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      host: constant.api(app.globalData.pord).url,
      mobile: wx.getStorageSync(storage.keys.mobile),
      courseRoundId: options.courseRoundId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.showLoading({
      title: "正在加载中..."
    })

    var that = this;

    wx.request({
      url: that.data.host + '/coach/course-rounds/' + that.data.courseRoundId + '/assessment?mobile=' + that.data.mobile,
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: function (res) {
        if (res.data.code == "0") {
          that.setData({
            basicData: res.data.data.basicData,
            postureJoint: res.data.data.postureJoint
          });

          if (that.data.basicData) {
            that.setData({
              restingHeartRate: that.data.basicData.resting_heart_rate ? that.data.basicData.resting_heart_rate : '',
              maxHeartRate: that.data.basicData.max_heart_rate ? that.data.basicData.max_heart_rate : '',
              bobi: that.data.basicData.bobi ? that.data.basicData.bobi : '',
              cardiovascular: that.data.basicData.cardiovascular ? that.data.basicData.cardiovascular : '',
              vUp: that.data.basicData.v_up ? that.data.basicData.v_up : '',
              vUpDesc: that.data.basicData.v_up_desc ? that.data.basicData.v_up_desc : '',
              staticSquat: that.data.basicData.static_squat ? that.data.basicData.static_squat : '',
              staticSquatDesc: that.data.basicData.static_squat_desc ? that.data.basicData.static_squat_desc : '',
              pushUp: that.data.basicData.push_up ? that.data.basicData.push_up : '',
              pushUpDesc: that.data.basicData.push_up_desc ? that.data.basicData.push_up_desc : '',
              diseases: that.data.basicData.disease_list ? that.data.basicData.disease_list : '',
              diseaseString: that.data.basicData.disease_string ? that.data.basicData.disease_string : '',
              allDiseases: that.data.basicData.all_diseases ? that.data.basicData.all_diseases : [],
              rectusAbdominisIsolation: that.data.basicData.rectus_abdominis_isolation ? that.data.basicData.rectus_abdominis_isolation : '',
              rectusAbdominisIsolationDesc: that.data.basicData.rectus_abdominis_isolation_desc ? that.data.basicData.rectus_abdominis_isolation_desc : ''
            })

            if (that.data.basicData.standard_bobi || that.data.basicData.standard_bobi == false) {
              that.setData({
                standardBobi: that.data.basicData.standard_bobi
              })
            }
          }

          if(that.data.postureJoint) {
            that.setData({
              obverseHead: that.data.postureJoint.obverse_head ? that.data.postureJoint.obverse_head : '',
              obverseHeadDesc: that.data.postureJoint.obverse_head_desc ? that.data.postureJoint.obverse_head_desc : '',
              obverseScapula: that.data.postureJoint.obverse_scapula ? that.data.postureJoint.obverse_scapula : '',
              obverseScapulaDesc: that.data.postureJoint.obverse_scapula_desc ? that.data.postureJoint.obverse_scapula_desc : '',
              obversePelvis: that.data.postureJoint.obverse_pelvis ? that.data.postureJoint.obverse_pelvis : '',
              obversePelvisDesc: that.data.postureJoint.obverse_pelvis_desc ? that.data.postureJoint.obverse_pelvis_desc : '',
              obverseKneeJoint: that.data.postureJoint.obverse_knee_joint ? that.data.postureJoint.obverse_knee_joint : '',
              obverseKneeJointDesc: that.data.postureJoint.obverse_knee_joint_desc ? that.data.postureJoint.obverse_knee_joint_desc : '',
              reverseHead: that.data.postureJoint.reverse_head ? that.data.postureJoint.reverse_head : '',
              reverseHeadDesc: that.data.postureJoint.reverse_head_desc ? that.data.postureJoint.reverse_head_desc : '',
              reverseCervicalVertebra: that.data.postureJoint.reverse_cervical_vertebra ? that.data.postureJoint.reverse_cervical_vertebra : '',
              reverseCervicalVertebraDesc: that.data.postureJoint.reverse_cervical_vertebra_desc ? that.data.postureJoint.reverse_cervical_vertebra_desc : '',
              reverseHipJoint: that.data.postureJoint.reverse_hip_joint ? that.data.postureJoint.reverse_hip_joint : '',
              reverseHipJointDesc: that.data.postureJoint.reverse_hip_joint_desc ? that.data.postureJoint.reverse_hip_joint_desc : '',
              reverseKneeJoint: that.data.postureJoint.reverse_knee_joint ? that.data.postureJoint.reverse_knee_joint : '',
              reverseKneeJointDesc: that.data.postureJoint.reverse_knee_joint_desc ? that.data.postureJoint.reverse_knee_joint_desc : '',
              reverseFoot: that.data.postureJoint.reverse_foot ? that.data.postureJoint.reverse_foot : '',
              reverseFootDesc: that.data.postureJoint.reverse_foot_desc ? that.data.postureJoint.reverse_foot_desc : '',
              kneeDirection: that.data.postureJoint.knee_direction ? that.data.postureJoint.knee_direction : '',
              kneeDirectionDesc: that.data.postureJoint.knee_direction_desc ? that.data.postureJoint.knee_direction_desc : '',
              thoracicVertebra: that.data.postureJoint.thoracic_vertebra ? that.data.postureJoint.thoracic_vertebra : '',
              thoracicVertebraDesc: that.data.postureJoint.thoracic_vertebra_desc ? that.data.postureJoint.thoracic_vertebra_desc : '',
              legMuscle: that.data.postureJoint.leg_muscle ? that.data.postureJoint.leg_muscle : '',
              legMuscleDesc: that.data.postureJoint.leg_muscle_desc ? that.data.postureJoint.leg_muscle_desc : '',
              hipJoint: that.data.postureJoint.hip_joint ? that.data.postureJoint.hip_joint : '',
              hipJointDesc: that.data.postureJoint.hip_joint_desc ? that.data.postureJoint.hip_joint_desc : '',
              shoulderJoint: that.data.postureJoint.shoulder_joint ? that.data.postureJoint.shoulder_joint : '',
              shoulderJointDesc: that.data.postureJoint.shoulder_joint_desc ? that.data.postureJoint.shoulder_joint_desc : '',
              ankleJoint: that.data.postureJoint.ankle_joint ? that.data.postureJoint.ankle_joint : '',
              ankleJointDesc: that.data.postureJoint.ankle_joint_desc ? that.data.postureJoint.ankle_joint_desc : ''
            })

            if (that.data.postureJoint.parallel || that.data.postureJoint.parallel == false) {
              that.setData({
                parallel: that.data.postureJoint.parallel
              })
            }
          }

          wx.hideLoading();
        } else {
          wx.hideLoading();

          wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 1000
          })
        }
      },
      fail: function (res) {
        wx.hideLoading();

        wx.showToast({
          title: '请求数据失败',
          icon: 'none',
          duration: 1000
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  bindClickPanel: function (e) {
    var that = this;
    const index = e.currentTarget.dataset.index
    that.data.showIndex[index] = !that.data.showIndex[index];
    that.setData({
      showIndex: that.data.showIndex
    })
  },

  formSubmit: function (e) {
    var that = this;
    that.setData({
      disabled: true
    })
    var data = e.detail.value;
    var postData = {
      basic_data: {
        resting_heart_rate: data.resting_heart_rate ? data.resting_heart_rate : null,
        max_heart_rate: data.max_heart_rate ? data.max_heart_rate : null,
        standard_bobi: (data.standard_bobi || data.standard_bobi == false) ? data.standard_bobi : null,
        bobi: data.bobi ? data.bobi : null,
        cardiovascular: data.cardiovascular ? data.cardiovascular : null,
        v_up: data.v_up ? data.v_up : null,
        static_squat: data.static_squat ? data.static_squat : null,
        push_up: data.push_up ? data.push_up : null,
        rectus_abdominis_isolation: data.rectus_abdominis_isolation ? data.rectus_abdominis_isolation : null
      },
      posture_joint: {
        obverse_head: data.obverse_head ? data.obverse_head : null,
        obverse_scapula: data.obverse_scapula ? data.obverse_scapula : null,
        obverse_pelvis: data.obverse_pelvis ? data.obverse_pelvis : null,
        obverse_knee_joint: data.obverse_knee_joint ? data.obverse_knee_joint : null,
        reverse_head: data.reverse_head ? data.reverse_head : null,
        reverse_cervical_vertebra: data.reverse_cervical_vertebra ? data.reverse_cervical_vertebra : null,
        reverse_hip_joint: data.reverse_hip_joint ? data.reverse_hip_joint : null,
        reverse_knee_joint: data.reverse_knee_joint ? data.reverse_knee_joint : null,
        reverse_foot: data.reverse_foot ? data.reverse_foot : null,
        knee_direction: data.knee_direction ? data.knee_direction : null,
        parallel: (data.parallel || data.parallel == false) ? data.parallel : null,
        thoracic_vertebra: data.thoracic_vertebra ? data.thoracic_vertebra : null,
        leg_muscle: data.leg_muscle ? data.leg_muscle : null,
        hip_joint: data.hip_joint ? data.hip_joint : null,
        shoulder_joint: data.shoulder_joint ? data.shoulder_joint : null,
        ankle_joint: data.ankle_joint ? data.ankle_joint : null
      },
      diseases: data.diseases ? data.diseases : null
    }

    wx.request({
      url: that.data.host + '/coach/course-rounds/' + that.data.courseRoundId + '/assessments?mobile=' + that.data.mobile,
      method: 'POST',
      data: postData,
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data.code == "0") {
          wx.showToast({
            title: res.data.message,
            icon: 'success',
            duration: 3000,
            mask: true,
            success: function () {
              setTimeout(function () {
                wx.navigateBack({
                  delta: 1
                })
              }, 1000)
            }
          });
        } else {
          that.setData({
            disabled: false
          })
          wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 3000,
            mask: true
          })
        }
      },
      fail: function (res) {
        that.setData({
          disabled: false
        })
        wx.showToast({
          title: '保存失败',
          icon: 'none',
          duration: 3000,
          mask: true
        })
      }
    });
  },

  showPopup: function (e) {
    var that = this;

    if (!that.data.pickerName) {
      var name = e.currentTarget.dataset.name;
      that.setData({
        popupShow: true,
        pickerName: name
      })

      if (name == 'diseases') {
        that.setData({
          oldAllDiseases: JSON.parse(JSON.stringify(that.data.allDiseases))
        })
      } else if (name == 'standardBobi') {
        that.setData({
          pickers: that.data.bobiTypes,
          pickerIndex: (!that.data.standardBobi && that.data.standardBobi == false) ? [1] : [0],
          tempPicker: (that.data.standardBobi || that.data.standardBobi == false) ? that.data.standardBobi : true
        })
      } else if(name == 'vUp') {
        that.setData({
          pickers: that.data.vUps,
          pickerIndex: that.getIndex(that.data.vUps,that.data.vUp),
          tempPicker: that.data.vUp ? that.data.vUp : that.data.vUps[0].value
        })
      } else if (name == 'staticSquat') {
        that.setData({
          pickers: that.data.staticSquats,
          pickerIndex: that.getIndex(that.data.staticSquats, that.data.staticSquat),
          tempPicker: that.data.staticSquat ? that.data.staticSquat : that.data.staticSquats[0].value
        })
      } else if (name == 'pushUp') {
        that.setData({
          pickers: that.data.pushUps,
          pickerIndex: that.getIndex(that.data.pushUps, that.data.pushUp),
          tempPicker: that.data.pushUp ? that.data.pushUp : that.data.pushUps[0].value
        })
      } else if (name == 'rectusAbdominisIsolation') {
        that.setData({
          pickers: that.data.rectusAbdominisIsolations,
          pickerIndex: that.getIndex(that.data.rectusAbdominisIsolations, that.data.rectusAbdominisIsolation),
          tempPicker: that.data.rectusAbdominisIsolation ? that.data.rectusAbdominisIsolation : that.data.rectusAbdominisIsolations[0].value
        })
      } else if (name == 'obverseHead') {
        that.setData({
          pickers: that.data.obverseHeads,
          pickerIndex: that.getIndex(that.data.obverseHeads, that.data.obverseHead),
          tempPicker: that.data.obverseHead ? that.data.obverseHead : that.data.obverseHeads[0]
        })
      } else if (name == 'obverseScapula') {
        that.setData({
          pickers: that.data.obverseScapulas,
          pickerIndex: that.getIndex(that.data.obverseScapulas, that.data.obverseScapula),
          tempPicker: that.data.obverseScapula ? that.data.obverseScapula : that.data.obverseScapulas[0]
        })
      } else if (name == 'obversePelvis') {
        that.setData({
          pickers: that.data.obversePelviss,
          pickerIndex: that.getIndex(that.data.obversePelviss, that.data.obversePelvis),
          tempPicker: that.data.obversePelvis ? that.data.obversePelvis : that.data.obversePelviss[0]
        })
      } else if (name == 'obverseKneeJoint') {
        that.setData({
          pickers: that.data.obverseKneeJoints,
          pickerIndex: that.getIndex(that.data.obverseKneeJoints, that.data.obverseKneeJoint),
          tempPicker: that.data.obverseKneeJoint ? that.data.obverseKneeJoint : that.data.obverseKneeJoints[0]
        })
      } else if (name == 'reverseHead') {
        that.setData({
          pickers: that.data.reverseHeads,
          pickerIndex: that.getIndex(that.data.reverseHeads, that.data.reverseHead),
          tempPicker: that.data.reverseHead ? that.data.reverseHead : that.data.reverseHeads[0]
        })
      } else if (name == 'reverseCervicalVertebra') {
        that.setData({
          pickers: that.data.reverseCervicalVertebras,
          pickerIndex: that.getIndex(that.data.reverseCervicalVertebras, that.data.reverseCervicalVertebra),
          tempPicker: that.data.reverseCervicalVertebra ? that.data.reverseCervicalVertebra : that.data.reverseCervicalVertebras[0]
        })
      } else if (name == 'reverseHipJoint') {
        that.setData({
          pickers: that.data.reverseHipJoints,
          pickerIndex: that.getIndex(that.data.reverseHipJoints, that.data.reverseHipJoint),
          tempPicker: that.data.reverseHipJoint ? that.data.reverseHipJoint : that.data.reverseHipJoints[0]
        })
      } else if (name == 'reverseKneeJoint') {
        that.setData({
          pickers: that.data.reverseKneeJoints,
          pickerIndex: that.getIndex(that.data.reverseKneeJoints, that.data.reverseKneeJoint),
          tempPicker: that.data.reverseKneeJoint ? that.data.reverseKneeJoint : that.data.reverseKneeJoints[0]
        })
      } else if (name == 'reverseFoot') {
        that.setData({
          pickers: that.data.reverseFoots,
          pickerIndex: that.getIndex(that.data.reverseFoots, that.data.reverseFoot),
          tempPicker: that.data.reverseFoot ? that.data.reverseFoot : that.data.reverseFoots[0]
        })
      } else if (name == 'kneeDirection') {
        that.setData({
          pickers: that.data.kneeDirections,
          pickerIndex: that.getIndex(that.data.kneeDirections, that.data.kneeDirection),
          tempPicker: that.data.kneeDirection ? that.data.kneeDirection : that.data.kneeDirections[0]
        })
      } else if (name == 'parallel') {
        that.setData({
          pickers: that.data.parallels,
          pickerIndex: (!that.data.parallel && that.data.parallel == false) ? [1] : [0],
          tempPicker: (that.data.parallel || that.data.parallel == false) ? that.data.parallel : true
        })
      } else if (name == 'thoracicVertebra') {
        that.setData({
          pickers: that.data.joints,
          pickerIndex: that.getIndex(that.data.joints, that.data.thoracicVertebra),
          tempPicker: that.data.thoracicVertebra ? that.data.thoracicVertebra : that.data.joints[0]
        })
      } else if (name == 'legMuscle') {
        that.setData({
          pickers: that.data.joints,
          pickerIndex: that.getIndex(that.data.joints, that.data.legMuscle),
          tempPicker: that.data.legMuscle ? that.data.legMuscle : that.data.joints[0]
        })
      } else if (name == 'hipJoint') {
        that.setData({
          pickers: that.data.joints,
          pickerIndex: that.getIndex(that.data.joints, that.data.hipJoint),
          tempPicker: that.data.hipJoint ? that.data.hipJoint : that.data.joints[0]
        })
      } else if (name == 'shoulderJoint') {
        that.setData({
          pickers: that.data.joints,
          pickerIndex: that.getIndex(that.data.joints, that.data.shoulderJoint),
          tempPicker: that.data.shoulderJoint ? that.data.shoulderJoint : that.data.joints[0]
        })
      } else if (name == 'ankleJoint') {
        that.setData({
          pickers: that.data.joints,
          pickerIndex: that.getIndex(that.data.joints, that.data.ankleJoint),
          tempPicker: that.data.ankleJoint ? that.data.ankleJoint : that.data.joints[0]
        })
      }
      
    }
  },

  diseaseChange: function (e) {
    var index = e.currentTarget.dataset.index;
    var that = this;
    
    that.data.allDiseases[index].check = !that.data.allDiseases[index].check;

    that.setData({
      allDiseases: that.data.allDiseases
    })
  },

  bindCancel: function () {
    if (this.data.pickerName == 'diseases') {
      this.setData({
        allDiseases: JSON.parse(JSON.stringify(this.data.oldAllDiseases))
      })
    }

    this.setData({
      popupShow: false,
      pickerName: ''
    })
  },

  bindConfirm: function () {
    if (this.data.pickerName == 'diseases') {
      var tempDiseaseString = '';
      var tempDiseases = new Array();
      for(var i=0;i<this.data.allDiseases.length;i++) {
        if (this.data.allDiseases[i].check) {
          tempDiseaseString = tempDiseaseString + this.data.allDiseases[i].description + ',';
          tempDiseases.push(this.data.allDiseases[i].value);
        }
      }
      this.setData({
        diseaseString: tempDiseaseString ? tempDiseaseString.substring(0, tempDiseaseString.length - 1) : '',
        diseases: tempDiseases
      })
    } else if (this.data.pickerName == 'standardBobi') {
      this.setData({
        standardBobi: this.data.bobiTypes[this.data.pickerIndex[0]].value
      })
    } else if (this.data.pickerName == 'vUp') {
      this.setData({
        vUp: this.data.vUps[this.data.pickerIndex[0]].value,
        vUpDesc: this.data.vUps[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'staticSquat') {
      this.setData({
        staticSquat: this.data.staticSquats[this.data.pickerIndex[0]].value,
        staticSquatDesc: this.data.staticSquats[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'pushUp') {
      this.setData({
        pushUp: this.data.pushUps[this.data.pickerIndex[0]].value,
        pushUpDesc: this.data.pushUps[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'rectusAbdominisIsolation') {
      this.setData({
        rectusAbdominisIsolation: this.data.rectusAbdominisIsolations[this.data.pickerIndex[0]].value,
        rectusAbdominisIsolationDesc: this.data.rectusAbdominisIsolations[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'obverseHead') {
      this.setData({
        obverseHead: this.data.obverseHeads[this.data.pickerIndex[0]].value,
        obverseHeadDesc: this.data.obverseHeads[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'obverseScapula') {
      this.setData({
        obverseScapula: this.data.obverseScapulas[this.data.pickerIndex[0]].value,
        obverseScapulaDesc: this.data.obverseScapulas[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'obversePelvis') {
      this.setData({
        obversePelvis: this.data.obversePelviss[this.data.pickerIndex[0]].value,
        obversePelvisDesc: this.data.obversePelviss[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'obverseKneeJoint') {
      this.setData({
        obverseKneeJoint: this.data.obverseKneeJoints[this.data.pickerIndex[0]].value,
        obverseKneeJointDesc: this.data.obverseKneeJoints[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'reverseHead') {
      this.setData({
        reverseHead: this.data.reverseHeads[this.data.pickerIndex[0]].value,
        reverseHeadDesc: this.data.reverseHeads[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'reverseCervicalVertebra') {
      this.setData({
        reverseCervicalVertebra: this.data.reverseCervicalVertebras[this.data.pickerIndex[0]].value,
        reverseCervicalVertebraDesc: this.data.reverseCervicalVertebras[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'reverseHipJoint') {
      this.setData({
        reverseHipJoint: this.data.reverseHipJoints[this.data.pickerIndex[0]].value,
        reverseHipJointDesc: this.data.reverseHipJoints[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'reverseKneeJoint') {
      this.setData({
        reverseKneeJoint: this.data.reverseKneeJoints[this.data.pickerIndex[0]].value,
        reverseKneeJointDesc: this.data.reverseKneeJoints[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'reverseFoot') {
      this.setData({
        reverseFoot: this.data.reverseFoots[this.data.pickerIndex[0]].value,
        reverseFootDesc: this.data.reverseFoots[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'kneeDirection') {
      this.setData({
        kneeDirection: this.data.kneeDirections[this.data.pickerIndex[0]].value,
        kneeDirectionDesc: this.data.kneeDirections[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'parallel') {
      this.setData({
        parallel: this.data.parallels[this.data.pickerIndex[0]].value
      })
    } else if (this.data.pickerName == 'thoracicVertebra') {
      this.setData({
        thoracicVertebra: this.data.joints[this.data.pickerIndex[0]].value,
        thoracicVertebraDesc: this.data.joints[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'legMuscle') {
      this.setData({
        legMuscle: this.data.joints[this.data.pickerIndex[0]].value,
        legMuscleDesc: this.data.joints[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'hipJoint') {
      this.setData({
        hipJoint: this.data.joints[this.data.pickerIndex[0]].value,
        hipJointDesc: this.data.joints[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'shoulderJoint') {
      this.setData({
        shoulderJoint: this.data.joints[this.data.pickerIndex[0]].value,
        shoulderJointDesc: this.data.joints[this.data.pickerIndex[0]].name
      })
    } else if (this.data.pickerName == 'ankleJoint') {
      this.setData({
        ankleJoint: this.data.joints[this.data.pickerIndex[0]].value,
        ankleJointDesc: this.data.joints[this.data.pickerIndex[0]].name
      })
    }

    this.setData({
      popupShow: false,
      pickerName: ''
    })
  },

  bindPickerChange: function (e) {
    this.setData({
      pickerIndex: e.detail.value
    })
  },

  getIndex: function (arr, value) {
    if(value) {
      for(var i=0; i<arr.length; i++) {
        if(arr[i].value == value) {
          return [i];
        }
      }
    } else {
      return [0];
    }
  }
})